package com.evan.review.ipc;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

import com.evan.review.R;

/**
 * 进程间通信(IPC)示例主入口
 * 展示Android中进程的概念和各种IPC通信方式
 */
public class IPCMainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ipc_main);

        // 进程基础知识
        Button btnProcessBasic = findViewById(R.id.btn_process_basic);
        btnProcessBasic.setOnClickListener(v -> {
            Intent intent = new Intent(this, ProcessBasicActivity.class);
            startActivity(intent);
        });

        // AIDL通信示例
        Button btnAidl = findViewById(R.id.btn_aidl);
        btnAidl.setOnClickListener(v -> {
            Intent intent = new Intent(this, AIDLDemoActivity.class);
            startActivity(intent);
        });

        // Messenger通信示例
        Button btnMessenger = findViewById(R.id.btn_messenger);
        btnMessenger.setOnClickListener(v -> {
            Intent intent = new Intent(this, MessengerDemoActivity.class);
            startActivity(intent);
        });

        // Binder通信示例
        Button btnBinder = findViewById(R.id.btn_binder);
        btnBinder.setOnClickListener(v -> {
            Intent intent = new Intent(this, BinderDemoActivity.class);
            startActivity(intent);
        });

        // ContentProvider通信示例
        Button btnContentProvider = findViewById(R.id.btn_content_provider);
        btnContentProvider.setOnClickListener(v -> {
            Intent intent = new Intent(this, ContentProviderDemoActivity.class);
            startActivity(intent);
        });

        // 文件共享通信示例
        Button btnFileSharing = findViewById(R.id.btn_file_sharing);
        btnFileSharing.setOnClickListener(v -> {
            Intent intent = new Intent(this, FileSharingDemoActivity.class);
            startActivity(intent);
        });

        // Socket通信示例
        Button btnSocket = findViewById(R.id.btn_socket);
        btnSocket.setOnClickListener(v -> {
            Intent intent = new Intent(this, SocketDemoActivity.class);
            startActivity(intent);
        });

        // 管道和消息队列示例
        Button btnPipeMsgQueue = findViewById(R.id.btn_pipe_msgqueue);
        btnPipeMsgQueue.setOnClickListener(v -> {
            Intent intent = new Intent(this, PipeAndMessageQueueActivity.class);
            startActivity(intent);
        });

        // 共享内存示例
        Button btnSharedMemory = findViewById(R.id.btn_shared_memory);
        btnSharedMemory.setOnClickListener(v -> {
            Intent intent = new Intent(this, SharedMemoryActivity.class);
            startActivity(intent);
        });

        // 广播通信示例
        Button btnBroadcast = findViewById(R.id.btn_broadcast);
        btnBroadcast.setOnClickListener(v -> {
            Intent intent = new Intent(this, BroadcastDemoActivity.class);
            startActivity(intent);
        });

        // IPC方式比较
        Button btnCompare = findViewById(R.id.btn_ipc_compare);
        btnCompare.setOnClickListener(v -> {
            new androidx.appcompat.app.AlertDialog.Builder(this)
                    .setTitle("IPC方式比较")
                    .setMessage("各种IPC方式适用场景比较：\n\n" +
                            "1. AIDL: 适用于复杂数据交互和跨进程方法调用\n" +
                            "2. Messenger: 适用于简单的跨进程通信，单向或简单的双向\n" +
                            "3. Binder: 系统服务通信的基础，AIDL和Messenger底层实现\n" +
                            "4. ContentProvider: 适用于共享结构化数据\n" +
                            "5. 文件共享: 简单但不实时，适用于对实时性要求低的场景\n" +
                            "6. Socket: 适用于网络通信，也可用于本地进程通信\n" +
                            "7. 管道: 低级别的单向数据流通信\n" +
                            "8. 消息队列: 适用于异步通信场景\n" +
                            "9. 共享内存: 高性能、无需拷贝，但需自行处理同步\n" +
                            "10. 广播: 适用于发布/订阅模式，一对多通信")
                    .setPositiveButton("了解", null)
                    .show();
        });
    }
} 